// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie;

import java.util.ArrayList;
import zombie.debug.DebugLog;
import zombie.network.GameServer;

public class TimeDebugger {
    ArrayList<Long> records = new ArrayList();
    ArrayList<String> recordStrings = new ArrayList();
    String name = "";

    public TimeDebugger(String _name) {
        this.name = _name;
    }

    public void clear() {
        if (GameServer.bServer) {
            this.records.clear();
            this.recordStrings.clear();
        }
    }

    public void start() {
        if (GameServer.bServer) {
            this.records.clear();
            this.recordStrings.clear();
            this.records.add(System.currentTimeMillis());
            this.recordStrings.add("Start");
        }
    }

    public void record() {
        if (GameServer.bServer) {
            this.records.add(System.currentTimeMillis());
            this.recordStrings.add(String.valueOf(this.records.size()));
        }
    }

    public void record(String note) {
        if (GameServer.bServer) {
            this.records.add(System.currentTimeMillis());
            this.recordStrings.add(note);
        }
    }

    public void recordTO(String note, int minTime) {
        if (GameServer.bServer && (Long)this.records.get(this.records.size() - 1) - (Long)this.records.get(this.records.size() - 2) > (long)minTime) {
            this.records.add(System.currentTimeMillis());
            this.recordStrings.add(note);
        }
    }

    public void add(zombie.TimeDebugger td) {
        if (GameServer.bServer) {
            String string = td.name;

            for (int _int = 0; _int < td.records.size(); _int++) {
                this.records.add((Long)td.records.get(_int));
                this.recordStrings.add(string + "|" + (String)td.recordStrings.get(_int));
            }

            td.clear();
        }
    }

    public void print() {
        if (GameServer.bServer) {
            this.records.add(System.currentTimeMillis());
            this.recordStrings.add("END");
            if (this.records.size() > 1) {
                DebugLog.log("=== DBG " + this.name + " ===");
                long long0 = (Long)this.records.get(0);

                for (int _int = 1; _int < this.records.size(); _int++) {
                    long long1 = (Long)this.records.get(_int - 1);
                    long long2 = (Long)this.records.get(_int);
                    String string = (String)this.recordStrings.get(_int);
                    DebugLog.log("RECORD " + _int + " " + string + " A:" + (long2 - long0) + " D:" + (long2 - long1));
                }

                DebugLog.log("=== END " + this.name + " (" + ((Long)this.records.get(this.records.size() - 1) - long0) + ") ===");
            } else {
                DebugLog.log("<<< DBG " + this.name + " ERROR >>>");
            }
        }
    }

    public long getExecTime() {
        return this.records.size() == 0 ? 0L : System.currentTimeMillis() - (Long)this.records.get(0);
    }
}
